# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Andreas Wagner <Andreas dot Wagner at em dot uni-frankfurt dot de>

pkgname=schroot
pkgver=1.6.13
pkgrel=3
pkgdesc="Allows users to execute shell commands under different root filesystems. (Successor to dchroot)."
url="https://packages.qa.debian.org/s/schroot.html"
license=('GPL3')
depends=('pam' 'boost-libs' 'e2fsprogs')
makedepends=('boost' 'cppunit' 'cmake' 'po4a')
optdepends=('btrfs-progs-unstable' 'lvm2')
arch=('loong64' 'x86_64')
conflicts=('dchroot')
replaces=('dchroot')
provides=('schroot' 'sbuild' 'dchroot')
backup=('etc/schroot/schroot.conf'
	'etc/schroot/arch32/config'
	'etc/schroot/arch32/copyfiles'
	'etc/schroot/arch32/mount'
	'etc/schroot/arch32/nssdatabases')
source=("https://deb.debian.org/debian/pool/main/s/$pkgname/${pkgname}_${pkgver}.orig.tar.xz"
	"https://deb.debian.org/debian/pool/main/s/schroot/schroot_$pkgver-3.debian.tar.xz"
	"schroot-gcc8-assert-fix.patch"
	'arch32-example'
	'arch32-config'
	'arch32-copyfiles'
	'arch32-mount'
	'arch32-nssdatabases'
	'pam.d.schroot.patch'
	'schroot-cppunit.patch')
sha256sums=('2d79ab1ae5ed5b06601ece4b20b7cc0ef0c0c486922693f9bedda927945cc6b3'
            'c636c1a9f4a02fe3729498c18a97730d7ae231a3ca1dd293c3f6d84a98b0a142'
            'b11cb87532001ebefd809e2e59750d1afc63551d603eed027c0ba0f3c075a0d6'
            '5ae07ef1b4525e9a6d9793d9d50cbf6d3f577f0a4001a2cde668d6817b03a6d5'
            '11730e71d6974a2172a86f2219ff0b394524567f4d75f11b7424dced2b40ed9b'
            'e67bb203b623ae9ecd4fe034546759c60780393d85bf87a907a94f114e425942'
            '8e6ea4cc6befc95a7a37edc590619a2ef0a060ad38c4d0a1830bb00c43becdb0'
            '2d564a13fbf330465aa00e442dcf6845263253be96f4776075be738b0018ef38'
            '68150bb913856b2f8b1d2423f3196a60a6ded7271678a9b651dc1ffbe6963196'
            '604a0b312f33a07e309d7857faf4edcc2985827da08a927c1d267dbb0946a240')

prepare() {
	cd re${pkgname}-${pkgver}
	grep -P '^\d' "$srcdir"/debian/patches/series | while read p; do
		patch -p1 -i "$srcdir"/debian/patches/$p
	done
	# https://bugs.archlinux.org/task/73481
	patch -p1 -i ../schroot-gcc8-assert-fix.patch
}

build() {
	cd re${pkgname}-${pkgver}
	export CFLAGS="$CFLAGS -ffat-lto-objects"
	export CXXFLAGS="$CXXFLAGS -ffat-lto-objects"
	export LDFLAGS="${LDFLAGS//-Wl,--as-needed}"
	mkdir -p build
	cd build
	cmake \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBEXECDIR=/usr/lib \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		..
	make
}

check() {
	cd re${pkgname}-${pkgver}/build
#	make -k check
}

package() {
	cd re${pkgname}-${pkgver}/build
	make DESTDIR="$pkgdir" install
	install -dm 755 "$pkgdir"/etc/schroot/arch32
	install -m 644 "$srcdir"/arch32-{config,mount,copyfiles,nssdatabases} "$pkgdir"/etc/schroot/arch32
	rename 'arch32-' '' "$pkgdir"/etc/schroot/arch32/*
	install -m 644 "$srcdir"/arch32-example "$pkgdir"/etc/schroot/chroot.d/arch32.conf.example
	patch -i "$srcdir"/pam.d.schroot.patch "$pkgdir"/etc/pam.d/schroot
}
